package java_thinking.unit_19._19_7_9;

import java_thinking.unit_19._19_1_6.Enums;

/**
 * @Desc:   19.7.3 更为简洁的管理枚举的办法，就是将一个enum嵌套在另一个enum内，
 * @author: cww
 * @DateTime: 2019/5/23 8:23
 */
public enum SecurityCategory {
    STOCK(Security.Stock.class), BOND(Security.Bond.class);
    Security[] values;
    SecurityCategory(Class<? extends Security> kind) {
        values = kind.getEnumConstants();
    }

    /**
     * enum公共类型组合
     */
    interface Security {
        enum Stock implements Security {
            SHORT, LONG, MARGIN
        }
        enum Bond implements Security {
            MUNICIPAL, JUNK
        }
    }
    public Security randomSelection() {
        return Enums.random(values);
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            SecurityCategory category = Enums.random(SecurityCategory.class);
            System.out.println(category + ": " + category.randomSelection());
        }
    }
}
